<?php
/**
 * Created by PhpStorm.
 * User: wangxiaodan
 * Date: 2017/4/18
 * Time: 下午2:36
 */

/**
 * @return array
 * 记录管理员日志
 */
function add_admin_log($data, $request){
    $user = Auth::guard('admin')->user();
    $request->setTrustedProxies(array('10.32.0.1/16'));
    $ip = $request->getClientIp();
    \App\Models\AdminLogs::create([
        'admin_id'  => $user['id'],
        'log_info'  => $data,
        'log_ip'    => $ip,
        'log_time'  => \Carbon\Carbon::now(),
    ]);
}

/**
 * @return array
 * 检查角色是否有权限
 */
function permissionCheck($perm, $role){
    return $role->hasPermission($perm->name)?true:false;
}

/**
 * @return array
 * 检查用户是否有角色
 */
function roleCheck($role, $user){
    return $user->hasRole($role->name)?true:false;
}

function getAllMenu(){
    return	array(
        'spa' => array('name' => '单页管理', 'icon'=>'fa-map', 'sub_menu' => array(
            'spaLst' => array('name' => '单页列表', 'url'=>'admin/spa/lst'),
        )),
        'administrator' => array('name' => '管理员', 'icon'=>'fa-user', 'sub_menu' => array(
            'admin_list' => array('name' => '管理员列表', 'url'=>'admin/adminuser'),
            'role_manage' => array('name' => '角色管理', 'url'=>'admin/roles'),
            'perm_manage' => array('name' => '权限管理', 'url'=>'admin/permissions'),
        )),
    );
}
